package com.h2.ref.server.web.captcha.dao;

import java.util.HashMap;
import java.util.Map;

import com.h2.ref.server.web.captcha.CaptchaVO;

public class CaptchaDaoInMem {
   
   
   
   private Integer _lastId = 0;
   
   private Map<Integer, CaptchaVO> _captchas = new HashMap<Integer, CaptchaVO>();

   ////
   ////
   
   public CaptchaVO createSolution(String uid, String solution) {
      setLastId(getLastId() + 1);
      
      CaptchaVO captcha = new CaptchaVO();
      captcha.setId(getLastId());
      captcha.setUid(uid);
      captcha.setSolution(solution);
      
      return captcha;
   }

   public synchronized CaptchaVO removeCaptcha(Integer captchaId) {
      return getCaptchas().remove(captchaId);
   }
   
   public CaptchaVO getCaptcha(Integer captchaId) {
      return getCaptchas().get(captchaId);
   }

   /**
    * @return the captchas
    */
   public Map<Integer, CaptchaVO> getCaptchas() {
      return _captchas;
   }

   /**
    * @param captchas the captchas to set
    */
   public void setCaptchas(Map<Integer, CaptchaVO> captchas) {
      _captchas = captchas;
   }

   /**
    * @return the lastId
    */
   public Integer getLastId() {
      return _lastId;
   }

   /**
    * @param lastId the lastId to set
    */
   public void setLastId(Integer lastId) {
      _lastId = lastId;
   }
}
